<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>接口调试首页</title>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<script type="text/javascript" src="/js/Ajax141212.js"></script>
<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
</head>
<body>
<style>

.topnav{
	margin:0px auto;
	height:30px;
	background:#CCC;

}

</style>



<div class="topnav">
  <div style="margin:0px auto; width:1000px; height:30px; line-height:30px;">
<div style="display:inline-block;">
  测试机(118.190.115.50)</div>
  
  
  
  
    <span style="margin-left:0px;"><a href="/user/login">login</a></span> | 

  </div>

</div>
<div style="margin:0px auto; margin-top:10px; width:1000px;">
  <ul>
    <li>接口名称：获取令牌</li>
    <li>接口地址：<?php echo $gate?></li>
    <li>接口方法：POST</li>
  </ul>
</div>

<br>
<table align="center" width="1000" cellpadding="0" cellspacing="1" style="border:1px solid #CCC">
  <form id="requestform">
  <tr bgcolor="#EEE" height="24">
    <td width="120">参数名</td>
    <td width="400">参数</td>
    <td>必填</td>
    <td>类型</td>
    <td>说明</td>
  </tr>
  <tr bgcolor="#F9F9F9" height="24">
    <td>grant_type</td>
    <td><input name="grant_type" type="text" value='authorization_code'/></td>
    <td>是</td>
    <td>string</td>
    <td></td>
  </tr>
  <tr bgcolor="#F9F9F9" height="24">
    <td>client_id</td>
    <td><input name="client_id" type="text" value='testclient'/></td>
    <td>是</td>
    <td>string</td>
    <td></td>
  </tr>
  <tr bgcolor="#F9F9F9" height="24">
    <td>client_secret</td>
    <td><input name="client_secret" type="text" value='testpass'/></td>
    <td>是</td>
    <td>string</td>
    <td></td>
  </tr>
  <tr bgcolor="#F9F9F9" height="24">
    <td colspan="5" align="center"><input type="button" value="CURL请求" onclick="request_curl()"/> <input type="button" value="直接请求" onclick="request()"/></td>
  </tr>
  </form>
</table>
<script language="javascript">

var host = {"name":"测试机(118.190.115.50)","oauth":"http:\/\/o.aidiaowu.com:8083","yuxun":"http:\/\/yuxun.aidiaowu.com:8083"};
var api_id = 1;
var api = {"id":1,"cid":0,"name":"获取令牌","host":"oauth","url":"\/oauth2\/token","method":"POST","isAuth":false,"params":[{"name":"grant_type","necessary":true,"type":"string","default":"password","intro":""},{"name":"username","necessary":true,"type":"string","default":"18618353136","intro":""},{"name":"password","necessary":true,"type":"string","default":"","intro":""},{"name":"client_id","necessary":true,"type":"string","default":"d813272ec72a5ad7","intro":""}]};
var isAuth = false;
var url = "/oauth2/token";
var method = "POST";
var params = [{"name":"grant_type","necessary":true,"type":"string","default":"password","intro":""},{"name":"username","necessary":true,"type":"string","default":"18618353136","intro":""},{"name":"password","necessary":true,"type":"string","default":"","intro":""},{"name":"client_id","necessary":true,"type":"string","default":"d813272ec72a5ad7","intro":""}];
var access_token = "";
console.log(api);
console.log(params);
	
function request_curl(){
	
	var grant_type = $('#grant_type').val();
	

	var $form = $('#requestform');
	
	$form.attr('method', 'POST');

	//$form.append($('<input type="text" name="grant_type" value="'+grant_type+'"/>'));  
	
	$form.attr('action', "/client/async-authorize");
	$form.submit();

}

/**
 * 直接请求
 */
function request(){

	var request_url = (api.host == "oauth") ? host.oauth+api.url : host.yuxun+api.url;
	console.log(request_url);

	var $form = $('#requestform');
	
	console.log(api);
	
	if(api.method == "GET"){

		$form.attr('method', 'GET');
		$form.attr('target', '_blank');
		$form.attr('action', request_url);
		
		if(access_token != ""){
			$form.append($('<input type="text" name="access_token" value="'+access_token+'"/>'));  
		}
		
		$form.submit();
	}else if(api.method == "POST"){
		
		$form.attr('method', 'POST');
		$form.attr('target', '_blank');
		$form.attr('action', request_url);
		
		if(access_token != ""){
			$form.append($('<input type="text" name="access_token" value="'+access_token+'"/>'));  
		}
		
		$form.submit();
	}
	

}


</script>
</body>
</html>